#define _CRT_SECURE_NO_WARNINGS 1
#pragma once

# if 0
#include<iostream>
using namespace std;
int main()
{
	long long* arr = new long long[2025];
	arr[1] = arr[2] = arr[3] = 1;
	for (int i = 4; i <= 2023; i++)
	{
		arr[i] = ((arr[i - 1] + arr[i - 2] + arr[i - 3]) % 100000 + 100000) % 100000;
	}
	cout << arr[2023]  << endl;
	delete[] arr;
	
	return 0;
}

#endif

#if 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
struct Stu
{
	string name;
	int chinese;
	int math;
	int english;
	Stu(string n, int c, int m, int e) :name(n), chinese(c), math(m), english(e),sum(0),pid(0)
	{}
	Stu()
	{}
	int sum;
	int pid;
};
int main()
{
	int n;
	cin >> n;
	vector<Stu> v;
	v.resize(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i].name >> v[i].chinese >> v[i].math >> v[i].english;
		v[i].sum = v[i].math + v[i].chinese + v[i].english;
		v[i].pid = i;
	}

	//根据总分排降序，分数一样按照pid升序排序
	auto cmp = [](const Stu& l,const Stu& r) {
		
		return l.sum == r.sum ? l.pid < r.pid : l.sum > r.sum;
	};
	sort(v.begin(), v.end(),cmp);
	cout << v[0].name <<" " <<  v[0].chinese << " "  <<  v[0].math << " "<< v[0].english << endl;
	return 0;
}	
#endif


#if 0
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;

	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		int t = i;
		while (t > 0)
		{
			int d = t % 10;
			if (d == 2 || d == 0 || d == 3)
			{
				ans += i;
				break;
			}
			t /= 10;
		}
	}
	cout << ans << endl;
	return 0;
}
#endif

#include<iostream>
#include<stack>
#include<algorithm>
#include<vector>
using namespace std;

struct TreeNode
{
	TreeNode* left;
	TreeNode* right;
	char ch;
	TreeNode(char c)
		:left(nullptr),right(nullptr),ch(c)
	{}
};
//前序遍历
void PreOrder(TreeNode* root)
{
	if (root == nullptr)	return;
	cout << root->ch;
	PreOrder(root->left);
	PreOrder(root->right);
}
TreeNode* GetNewNode(char ch)
{
	if (ch == '*')
		return nullptr;
	return new TreeNode(ch);
}

TreeNode* findRoot(TreeNode* root,char ch)
{
	if (!root) return nullptr;

	if (root->ch == ch)
		return root;
	
	TreeNode* leftAns = findRoot(root->left, ch);
	if (leftAns != nullptr)
		return leftAns;
	else
		return findRoot(root->right, ch);
}
int main()
{
	int n;
	cin >> n;
	char v1, v2, v3;
	cin >> v1 >> v2 >> v3;
	//根 左  右
	TreeNode* root = GetNewNode(v1);
	root->left = GetNewNode(v2);
	root->right = GetNewNode(v3);

	for (int i = 0; i < n - 1; i++)
	{
		cin >> v1 >> v2 >> v3;
		
		TreeNode* pRoot = findRoot(root, v1);//找到v1为根节点的这颗子树
		//链接左右子树
		pRoot->left = GetNewNode(v2);
		pRoot->right = GetNewNode(v3);
	}

	//遍历
	PreOrder(root);
	return 0;
}